<template>
<div class="collapse-head">
    <div class="head-main" @mouseenter="showDetails" @mouseleave="closeDetails">
        <h5>{{data.title.value}}</h5>
        <span>{{(data.score.value * 100).toFixed(1)}}%</span>
    </div>
    <div class="desc">
        <p>{{data.description.value}}</p>
    </div>
    <div class="desc-list" v-if="showList" ref="listDOM" @mouseenter="showDetails" @mouseleave="closeDetails">
        <ul>
            <li v-for="item in data.details.value.items" :key="item.url">
                <p>{{item.url}}</p>
            </li>
        </ul>
    </div>
</div>
</template>

<script>
import {
    computed,
    toRefs,
    ref
} from 'vue'
export default {
    name: "collapseHead",
    props: {
        data: {
            type: Object,
            required: true
        }
    },
    setup(props) {
        const data = toRefs(props.data);
        const listDOM = ref(null)
        const showList = computed(() => {
            return data.details.value.items.length > 0;
        })

        function showDetails() {
            if (listDOM.value !== null) {
                listDOM.value.style.display = "block"
            }
        }

        function closeDetails() {
            if (listDOM.value !== null) {
                listDOM.value.style.display = "none"
            }
        }
        return {
            data,
            showList,
            listDOM,
            showDetails,
            closeDetails
        }
    }
}
</script>

<style lang="scss" scoped>
.collapse-head {
    position: relative;
    width: 100%;
    height: auto;

    .head-main {
        width: 100%;
        display: flex;
        line-height: 45px;
        background: #f8f8f8;
        border-bottom: 1px solid #eee;
        padding: 0 10px;
        box-sizing: border-box;
        cursor: pointer;

        h5 {
            flex: 1;
            font-size: 16px;
            color: #333;
            font-weight: 600;
        }

        span {
            font-size: 13px;
            color: #888;
        }
    }

    .desc {
        background: #efefef;
        padding: 15px;
        box-sizing: border-box;
        border: 1px solid #eee;
        line-height: 22px;
        font-size: 15px;
        color: #666;
        z-index: 100;

    }

    .desc-list {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        border-radius: 6px;
        padding: 15px;
        box-sizing: border-box;
        background: #fefefe;
        z-index: 100;
        display: none;
        animation: show .5s ease forwards;

        ul li {
            p {
                font-size: 14px;
                color: #666;
                line-height: 32px;
                border-bottom: 1px solid #eee;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
        }
    }
}

@keyframes show {
    from {
        opacity: 0;
        margin-top: 36px;
    }

    to {
        opacity: 1;
        margin-top: 46px;
    }
}
</style>
